from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from django.contrib.auth.models import Group, Permission
from meiduo_admin.serializer.groups import GroupSerializer
from meiduo_admin.serializer.permission import PermissionSerializer
from meiduo_admin.utils import PageNum

# 分组表的增删改查
class GroupView(ModelViewSet):

    # 指定权限
    permission_classes = [IsAdminUser]
    # 指定序列化器
    serializer_class = GroupSerializer
    # 指定查询集
    queryset = Group.objects.all()
    # 指定分页器
    pagination_class = PageNum

    def simple(self,request):
        # 查询所有权限类型
        permission = Permission.objects.all()
        # 返回权限类型
        ser = PermissionSerializer(permission,many=True)
        return Response(ser.data)